package Examin.WangYi;

import java.util.HashSet;
import java.util.Scanner;

public class third {
    static long res = 0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] s1 = s.split(" ");
        int n = Integer.parseInt(s1[0]);//点数
        int m = Integer.parseInt(s1[1]);//边数
        Long[] lenth = new Long[n+1];
        //记录边长
        for (int i = 1; i <= n; i++) {
            lenth[i] = scanner.nextLong();
        }
        int[][] graph = new int[n+1][n+1];
        //为1表示两个点联通，为0表示不连通
        //记录连通
        for (int i = 0; i < m; i++) {
            int i1 = scanner.nextInt();
            int i2 = scanner.nextInt();
            graph[i1][i2] = 1;
            graph[i2][i1] = 1;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if(graph[i][j] == 1){
                    dfs(graph,n,i,j);
                }
            }
        }
        System.out.println(res);
    }

    private static void dfs(int[][] graph, int n, int i, int j){

        if(i<1 || j<1 || i>n || j>n || graph[i][j]==0){
            return;
        }

        graph[i][j]=0;
        graph[j][i]=0;

        dfs(graph,n,i+1,j);
        dfs(graph,n,i-1,j);
        dfs(graph,n,i,j+1);
        dfs(graph,n,i,j-1);


    }

    //判断当前图是不是可达
    private static boolean isValid(int[][] graph, int n){
        //保存节点的下标
        HashSet<Integer> set = new HashSet<Integer>();
        //判断删除某个边后，是不是联通图
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if(graph[i][j] == 1){
                    set.add(i);
                    set.add(j);
                }
            }
            //如果遍历一遍几个点都能走到，说明是联通的
            if(set.size()==n){
                return true;
            }
        }
        return false;
    }
}
